<?php
	/**
	*Author 雷日锦 362606856@qq.com 
	*控制器自动生成
	*/
	if(!defined("ROOT_PATH")) exit("die Access ");
	class ymdian_applyControl extends skymvc{
		
		public function __construct(){
			parent::__construct();
		}
		
		public function onDefault(){
			$where=" siteid=".SITEID;
			$url=APPADMIN."?m=ymdian_apply&a=default";
			$limit=20;
			$start=get("per_page","i");
			$option=array(
				"start"=>intval(get_post('per_page')),
				"limit"=>$limit,
				"order"=>" id DESC",
				"where"=>$where
			);
			$rscount=true;
			$data=M("ymdian_apply")->select($option,$rscount);
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$this->smarty->assign(
				array(
					"data"=>$data,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"url"=>$url
				)
			);
			$this->smarty->display("ymdian_apply/index.html");
		}
		
		public function onStatus(){
			$id=get_post('id',"i");
			$status=get_post("status","i");
			M("ymdian_apply")->update(array("status"=>$status),"id=$id");
			$this->goall("状态修改成功",0);
		}
		
		public function onSuccess(){
			$id=get_post('id',"i");
			$status=2;
			$row=M("ymdian_apply")->selectRow("id=".$id);
			if($row){
				$ymdian=M("ymdian")->selectRow("sc_id=".$row['sc_id']." AND status<11 ");
				if($ymdian){
					$this->goAll("审核失败，夜猫店已经有店铺了",1);
				}
				$sc=M("site_city")->selectRow("sc_id=".$row['sc_id']);
				$shopid=M("ymdian")->insert(array(
					"title"=>$sc['title'],
					"sc_id"=>$row['sc_id'],
					"siteid"=>$row['siteid'],
					"dateline"=>time(),
					"nickname"=>$row['nickname'],
					"telephone"=>$row['telephone']
					
				));
				$salt=rand(1000,9999);
				M("ymdian_admin")->insert(
					array(
						"adminname"=>$row['telephone'],
						"password"=>umd5($row['telephone'].$salt),
						"salt"=>$salt,
						"siteid"=>$row['siteid'],
						"shopid"=>$shopid
					)
				);
			}
			M("ymdian_apply")->update(array("status"=>$status),"id=$id");
			$this->goall("申请审核成功",0);
		}
		
		public function onDelete(){
			$id=get_post('id',"i");
			M("ymdian_apply")->delete("id=".$id);
			$this->goall("删除成功",0);
		}
		
		
	}

?>